import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { TPromotionCardConfig } from "../../../Message/Db/Tables/TPromotionCardConfig";
import { StringHelper } from "../../../com/gengine/utils/StringHelper";
import { ItemData } from "./info/ItemData";
type int = number;
//class PromotionCardConfig
    
    export  class PromotionCardConfig
    {
        constructor()
        {
            
            this._map = new Map<any, any> /* flash.utils.Dictionary */();
            if (PromotionCardConfig._instance != null) 
            {
                throw new Error("PromotionCardConfig 单例");
            }
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc1=ConfigManager.instance.getJSONByFileName("t_promotion_card_config.json");
            this.write(loc1);
            return;
        }

        /* internal  */write(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new TPromotionCardConfig();
                loc1.name = StringHelper.getString(loc2.name);
                loc1.rewards = StringHelper.getString(loc2.rewards);
                loc1.type = loc2.type;
                this._map[loc1.type] = loc1;
            }
            return;
        }

        public getCardNameByType(arg1: int): string
        {
            var loc1=this._map[arg1] as TPromotionCardConfig;
            if (loc1 != null) 
            {
                return loc1.name;
            }
            return "推广卡";
        }

        public getRewardsByType(arg1: int, arg2: int=1): Array<any>
        {
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc6=0;
            var loc7=null;
            var loc8=0;
            var loc1=[];
            var loc2;
            if (loc2 = this._map[arg1] as TPromotionCardConfig) 
            {
                loc6 = (loc3 = loc2.rewards.split("#")).length;
                loc8 = 0;
                while (loc8 < loc6) 
                {
                    loc5 = (loc4 = loc3[loc8]).split(",");
                    if (arg2 != 1) 
                    {
                        if (arg2 == 2) 
                        {
                            loc1.push(int(loc5[0]));
                        }
                    }
                    else 
                    {
                        (loc7 = new ItemData(int(loc5[0]))).itemAmount = int(loc5[1]);
                        loc1.push(loc7);
                    }
                    ++loc8;
                }
            }
            return loc1;
        }

        public static get instance(): PromotionCardConfig
        {
            if (PromotionCardConfig._instance == null) 
            {
                PromotionCardConfig._instance = new PromotionCardConfig();
            }
            return PromotionCardConfig._instance;
        }

        /* internal */ /* var */_map: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_instance: PromotionCardConfig;
    }
